<?xml version='1.0' encoding='UTF-8'?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:finantial="http://java.sun.com/jsf/composite/components/finantial"
      xmlns:composite="http://java.sun.com/jsf/composite"
      xmlns:ui="http://java.sun.com/jsf/facelets">


    <composite:interface>

        <composite:attribute  type="br.rmpestano.finantial.model.FinantialMonth" name="month" required="true"  />
        <composite:attribute name="id" />


    </composite:interface>

    <composite:implementation>
        <p:outputPanel id="month_#{cc.attrs.month.monthIndex}">
            <ui:param name="m" value="#{cc.attrs.month}"/>
            <table width="100%">
                <tr>
                    <td align="right">
                        <h:panelGrid columns="3" style="margin-top: -15px">
                            <h:graphicImage library="images" title="#{msg['month.balance']}" id="img" name="#{tabBean.saldoMensal eq 0 ? 'money.png' : tabBean.saldoMensal > 0 ? 'money_add.png' : 'money_delete.png'}" style="padding-top: 6px;padding-right: 2px;"/>
                            <finantial:label for="img" value=":" style="font-weight: bold"/>
                            <h:outputText  value="#{tabBean.saldoMensal}" style="font-size: 10px;font-weight: bold;text-decoration: underline;">
                                <f:convertNumber pattern="#,###,##0.00" currencyCode="BRL" type="currency"/>
                            </h:outputText>
                        </h:panelGrid>
                    </td>
                </tr>
            </table>

            <p:accordionPanel  activeIndex="#{tabBean.financesActiveIndex}" cache="false" autoHeight="false" effect="bounceslide" tabChangeListener="#{tabBean.tabChange}" collapsible="true" fillSpace="true" onTabChangeUpdate="msg,month_#{cc.attrs.month.monthIndex}">
                <p:tab title="#{msg['finance.label.tipo.outcome']}s">
                    <p:outputPanel rendered="#{(tabBean.userOutcomesSize ne 0) and (m.showMonthOutcomes == true)}">
                            <p:dataTable id="outcome_table#{cc.attrs.month.monthIndex}" var="d" value="#{tabBean.currentUserOutcomesInTheMonth}" lazy="true"  paginator="true" rows="5"
                                         paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" 
                                         emptyMessage="Nenhum registro encontrado"  rowIndexVar="rowIndex" rowStyleClass="#{empty rowIndex or rowIndex mod 2 ne 0 ? 'even-row' : ''}" paginatorPosition="bottom" rowsPerPageTemplate="5,10,15,#{tabBean.userOutcomesSize > 15 ? tabBean.userOutcomesSize : ''}">
                                <p:column sortBy="#{d.date}" parser="date" >
                                    <f:facet name="header">
                                        <finantial:label value="#{msg['finance.label.data']}"/>
                                    </f:facet>
                                    <p:commandLink style="text-decoration: none">
                                        <h:outputText value="#{d.date}" >
                                            <f:convertDateTime pattern="dd/MM/yyyy"/>
                                        </h:outputText>
                                    </p:commandLink>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <finantial:label value="#{msg['login.label.username']}"/>
                                    </f:facet>
                                    <p:commandLink  style="text-decoration: none">
                                        <h:outputText value="#{d.user}" />
                                    </p:commandLink>
                                </p:column>
                                <p:column >
                                    <f:facet name="header">
                                        <finantial:label value="#{msg['finance.label.descricao']}"/>
                                    </f:facet>
                                    <p:commandLink style="text-decoration: none; white-space: nowrap ">
                                        <h:outputText value="#{d.description}"/>
                                    </p:commandLink>
                                </p:column>
                                <p:column filterBy="#{d.type.description}" filterOptions="#{tabBean.outcomeFilterOptions}"
                                          filterMatchMode="exact" >
                                    <f:facet name="header">
                                        #{msg['finance.label.tipo']}
                                    </f:facet>
                                    <p:commandLink  style="text-decoration: none">
                                        <h:outputText  value="#{d.type}"/>
                                    </p:commandLink>
                                </p:column>
                                <p:column sortBy="#{d.value}" parser="number">
                                    <f:facet name="header">
                                        #{msg['finance.label.valor']}
                                    </f:facet>
                                    <p:commandLink>
                                        <h:outputText style="font-weight: bold;" value="#{d.value}">
                                            <f:convertNumber pattern="#,###,##0.00" currencyCode="BRL" type="currency"/>
                                        </h:outputText>
                                    </p:commandLink>
                                </p:column>

                                <p:column style="width: 75px!important">
                                    <f:facet name="header">
                                        #{msg['finance.label.operacoes']}
                                    </f:facet>
                                    <div style="display: inline;margin-left: 5px" >
                                        <p:commandLink title="#{msg['outcome-edit']}" action="#{financeBean.prepareEditOutcome(d)}"  oncomplete="editModal.show()" process="@this"  update="edit_panel,months_form:msg" >
                                            <h:graphicImage library="images" name="edit20x20.png" style="border: none;"/>
                                        </p:commandLink>
                                        &#160;&#160;
                                        <p:commandLink title="#{msg['outcome-remove']}" action="#{financeBean.prepareRemoveOutcome(d)}" oncomplete="removeModal.show()" process="@this" update="remove_panel,months_form:msg">
                                            <h:graphicImage library="images" name="garbage20x20.png" style="border: none;"/>
                                        </p:commandLink>
                                    </div>
                                </p:column>

                                <f:facet name="footer" >
                                    <table width="100%">
                                        <tr>
                                            <td align="center">
                                                <p:panel style="width: 200px;min-height: 25px;height: auto ">
                                                    <div align="center">
                                                        <h:outputLabel style="font-weight: bold" for="total_depesa" value="#{msg['finance.label.total']}:"/>
                                                        <h:outputText style="padding-left: 5px;color:#{themeService.themeProperties.FINANCE_FOOTER_COLOR}" id="total_depesa" value="#{tabBean.totalOutcomeInThemonth}">
                                                            <f:convertNumber pattern="#,###,##0.00" currencyCode="BRL" type="currency"/>
                                                        </h:outputText>
                                                    </div>
                                                </p:panel>
                                            </td>
                                        </tr>
                                    </table>
                                </f:facet>

                            </p:dataTable>
                        </p:outputPanel>
                        <div align="center" style="padding-top: 8px;" >
                            <p:commandButton title="#{msg['finance.tooltip.add-outcome']}" action="#{financeBean.prepareAddMonthOutcome(m)}" value="#{msg['new-outcome']}" async="true" immediate="true" update="month_panel,month_outcome_msg,monthDlgPanel"  oncomplete="monthModal.show()" />
                        </div>
                        <div align="center" style="padding-top: 8px;">
                            <h:outputText value="#{msg['no-outcome']}" style="color: red;font-size: 14px;padding-bottom: 10px" rendered="#{(tabBean.userOutcomesSize eq 0) and (m.showMonthOutcomes == true)}"/>
                        </div>
                </p:tab>
                <p:tab title="#{msg['finance.label.tipo.income']}s">
                    <p:outputPanel rendered="#{(tabBean.userIncomesSize ne 0) and (m.showMonthIncomes == true)}">
                        <p:dataTable var="r" id="income_table#{cc.attrs.month.monthIndex}" dynamic="true" value="#{tabBean.currentUserIncomesInTheMonth}" lazy="true" paginator="true" rows="5" paginatorPosition="bottom"
                                      paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowIndexVar="rowIndex" rowStyleClass="#{empty rowIndex or rowIndex mod 2 ne 0 ? 'even-row' : ''}"
                                      emptyMessage="Nenhum registro encontrado" rowsPerPageTemplate="5,10,15,#{tabBean.userIncomesSize > 15 ? tabBean.userIncomesSize : ''}" style="border: none">
                            <p:column  sortBy="#{r.date}" parser="date" >
                                <f:facet name="header">
                                    <finantial:label value="#{msg['finance.label.data']}"/>
                                </f:facet>
                                <p:commandLink title="#{msg['finance.tooltip.edit-remove']}" style="text-decoration: none">
                                    <h:outputText value="#{r.date}" >
                                        <f:convertDateTime pattern="dd/MM/yyyy"/>
                                    </h:outputText>
                                </p:commandLink>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <finantial:label value="#{msg['login.label.username']}"/>
                                </f:facet>
                                <p:commandLink  style="text-decoration: none">
                                    <h:outputText value="#{r.user}" />
                                </p:commandLink>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <finantial:label value="#{msg['finance.label.descricao']}"/>
                                </f:facet>
                                <p:commandLink value="#{r.description}" style="text-decoration: none"/>
                            </p:column>
                            <p:column filterBy="#{r.type.description}" filterOptions="#{tabBean.incomeFilterOptions}"
                                      filterMatchMode="exact" >
                                <f:facet name="header">
                                    <finantial:label value="#{msg['finance.label.tipo']}"/>
                                </f:facet>
                                <p:commandLink  style="text-decoration: none">
                                        <h:outputText  value="#{r.type}"/>
                                    </p:commandLink>
                            </p:column>
                            <p:column  sortBy="#{r.value}" parser="number">
                                <f:facet name="header">
                                    #{msg['finance.label.valor']}
                                </f:facet>
                                <p:commandLink>
                                    <h:outputText style="font-weight: bold;" value="#{r.value}">
                                        <f:convertNumber pattern="#,###,##0.00" currencyCode="BRL" type="currency"/>
                                    </h:outputText>
                                </p:commandLink>
                            </p:column>
                            <p:column style="width: 75px!important">
                                <f:facet name="header">
                                    #{msg['finance.label.operacoes']}
                                </f:facet>
                                <div style="display: inline;margin-left: 5px" >
                                    <p:commandLink title="#{msg['income-edit']}" action="#{financeBean.prepareEditIncome(r)}"  oncomplete="editModal.show()" process="@this"  update="edit_panel,months_form:msg" >
                                        <h:graphicImage style="border: none;" library="images" name="edit20x20.png"/>
                                    </p:commandLink>
                                    &#160;&#160;
                                    <p:commandLink  title="#{msg['income-remove']}" action="#{financeBean.prepareRemoveIncome(r)}" oncomplete="removeModal.show()" process="@this" update="remove_panel,months_form:msg">
                                        <h:graphicImage style="border: none;" library="images" name="garbage20x20.png"/>
                                    </p:commandLink>
                                </div>
                            </p:column>
                            <f:facet name="footer" >
                                <table width="100%">
                                    <tr>
                                        <td align="center">
                                            <p:panel style="width: 200px;min-height: 25px;height: auto ">
                                                <div align="center">
                                                     <h:outputLabel style="font-weight: bold" for="total_receita" value="#{msg['finance.label.total']}:"/>
                                                    <h:outputText style="padding-left: 5px;color:#{themeService.themeProperties.FINANCE_FOOTER_COLOR}" id="total_receita" value="#{tabBean.totalIncomeInTheMonth}">
                                                        <f:convertNumber pattern="#,###,##0.00" currencyCode="BRL" type="currency"/>
                                                    </h:outputText>
                                                </div>
                                            </p:panel>
                                        </td>
                                    </tr>
                                </table>
                            </f:facet>
                        </p:dataTable>
                    </p:outputPanel>
                    <div align="center" style="padding-top: 8px;" >
                        <p:commandButton title="#{msg['finance.tooltip.add-income']}"  action="#{financeBean.prepareAddMonthIncome(m)}" value="#{msg['new-income']}" async="true" immediate="true" update="month_panel,month_income_msg,monthDlgPanel"  oncomplete="monthModal.show()" />
                    </div>
                    <div align="center" style="padding-top: 8px;">
                        <h:outputText value="#{msg['no-income']}" style="color: red;font-size: 14px;padding-bottom: 10px" rendered="#{(tabBean.userIncomesSize eq 0) and (m.showMonthIncomes == true)}"/>
                    </div>

                </p:tab>
                <p:tab title="#{msg['tab.reports']}">
                    <p:dataTable value="#{reportBean.reports}" var="r" rowIndexVar="rowIndex" rowStyleClass="#{empty rowIndex or rowIndex mod 2 ne 0 ? 'even-row' : 'odd-row'}">
                        <f:facet name="header">
                            Relatórios Disponíveis
                        </f:facet>
                        <p:column>
                            <f:facet name="header">
                                Título
                            </f:facet>
                            #{r.title}
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                Descrição
                            </f:facet>
                            <h:outputText value="#{r.description}" escape="false"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                Tipo
                            </f:facet>
                            <h:selectOneMenu disabled="#{r.number eq reportBean.REPORT_NUMBER_THREE}" id="selectTipos" value="#{reportBean.tipoCorrente}">
                                <f:selectItems value="#{reportBean.tiposFinanca}" var="tipo" itemLabel="#{tipo eq reportBean.INCOME ? msg['finance.label.tipo.income'] : msg['finance.label.tipo.outcome']}" itemValue="#{tipo}"/>
                            </h:selectOneMenu>
                        </p:column>
                        <p:column style="width: 60px!important">
                            <f:facet name="header">
                                Visualisar
                            </f:facet>
                            <p:commandLink action="#{reportBean.prepareMonthReport(m)}"  oncomplete="monthReportsModal.show()" update="month_report_panel" process="@this selectTipos" >
                                <div align="center">
                                    <h:graphicImage style="border: none;" title="Visualisar relatório" library="images" name="report3.png"/>
                                </div>
                                <f:setPropertyActionListener value="#{r.number}" target="#{reportBean.currentReportNumber}"/>
                            </p:commandLink>
                        </p:column>
                    </p:dataTable>
                </p:tab>

            </p:accordionPanel>
        </p:outputPanel>

    </composite:implementation>



</html>


